local plymeta = FindMetaTable( "Player" )

CLASS_DEFAULT =
{
	Name = "Default",
	Speed = 230,
	PlayerModel = "models/player/gasmask.mdl",
	MaxHealth = 100,
	Loadout = function(ply)
		ply:Give("weapon_ze_m16a2")
		ply:GiveAmmo(120, "AR2", true)
		
		ply:Give("weapon_ze_usp")
		ply:GiveAmmo(9999, "Pistol", true)
	end
};
CLASS_SUPPORT =
{
	Name = "Support",
	Speed = 215,
	PlayerModel = "models/player/swat.mdl",
	MaxHealth = 100,
	Loadout = function(ply)
		ply:Give("weapon_ze_870")
		ply:GiveAmmo(32, "Buckshot", true)
		
		ply:Give("weapon_ze_usp")
		ply:GiveAmmo(9999, "Pistol", true)
	end
};
CLASS_EVADER =
{
	Name = "Evader",
	Speed = 245,
	PlayerModel = "models/player/phoenix.mdl",
	MaxHealth = 90,
	Loadout = function(ply)
		ply:Give("weapon_ze_mp5")
		ply:GiveAmmo(120, "SMG1", true)
		
		ply:Give("weapon_ze_usp")
		ply:GiveAmmo(9999, "Pistol", true)
	end
};

function plymeta:SpawnRound()
	self:StripWeapons()
	self:Spawn()
	self:SetHuman()
	self:UnSpectate()
end

function plymeta:Loadout()
	if not IsValid(self) or self:IsSpec() then return end
	
	self:StripAmmo()
	self:StripWeapons()
	
	if self:IsHuman() then
		self:SetHealth(self.Class.MaxHealth)
		self:SetMaxHealth(self.Class.MaxHealth)
		self:SetModel(self.Class.PlayerModel)
		self.Class.Loadout(self)
		GAMEMODE:SetPlayerSpeed(self, self.Class.Speed, self.Class.Speed)
		
		self.Loaded = true
	elseif self:IsZombie() then
		self:SetHealth(5000)
		self:SetMaxHealth(5000)
		self:Give("weapon_crowbar")
		self:SetModel("models/player/zombiefast.mdl")
		GAMEMODE:SetPlayerSpeed(self, 260, 260)
		
		self.Loaded = true
	end
end

function plymeta:SetHuman()
	self:SetTeam(TEAM_HUMAN)
	self:Loadout()
end

function SetClassCMD(ply, command, arg)
	class = arg[1]

	if class == "support" then
		ply.Class = CLASS_SUPPORT
	elseif class == "default" then
		ply.Class = CLASS_DEFAULT
	elseif class == "evader" then
		ply.Class = CLASS_EVADER
	end
	
	if GetRoundState() > 2 then
		PlayerMsg(ply, "You will be "..ply.Class.Name.." when you respawn.")
	else
		ply:StripWeapons()
		ply:Spawn()
		ply:UnSpectate()
		ply:SetHuman()
	end
end

function plymeta:SetZombie()
	if not IsValid(self) then return end
	
	self:SetTeam(TEAM_ZOMBIE)
	self:Loadout()
end

function plymeta:AddDamageDealt(dmginfo)
	local class = dmginfo:GetWeaponClass()
	local orig = math.floor(self.dealt/100)

	self.dealt = self.dealt + dmginfo:GetBaseDamage()
	local points = math.floor(self.dealt/100)
	
	self:AddExp(class, points - orig)
end

function plymeta:GetExp(class)
	return Data.RetrieveExp(self, class)
end

function plymeta:AddExp(class, amount)
	Data.StoreExp(self, class, Data.RetrieveExp(self, class) + amount)
end

function plymeta:SetExp(class, amount)
	Data.StoreExp(self, class, amount)
end